package org.easyframework.core.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @version:
 * @Description: 生成唯一序列号
 * @author: daiw
 * @date: 2018年10月12日 下午4:51:24
 */
public class GenerateOrderNumber {

	private static Map<Integer, String> prefixMap = new HashMap<Integer, String>();

	static {
		prefixMap.put(0, "O");
	}

	/**
	 * 根据类型生成订单号
	 * 
	 * @param orderType
	 *            订单类型
	 * @return
	 */
	public static String getOrderNumber(int orderType) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		String orderNumber = sdf.format(new Date());

		for (int i = 0; i < 6; i++) {
			orderNumber += (int) (Math.random() * 10);
		}
		orderNumber = prefixMap.get(orderType) + orderNumber;
		return orderNumber;
	}

	/**
	 * 生成订单号
	 * 
	 * @param orderType
	 *            订单类型
	 * @return
	 */
	public static String getOrderNumber() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		String orderNumber = sdf.format(new Date());

		for (int i = 0; i < 6; i++) {
			orderNumber += (int) (Math.random() * 10);
		}
		orderNumber = prefixMap.get(0) + orderNumber;
		return orderNumber;
	}

	/**
	 * 生成订单号
	 * 
	 * @param orderType
	 *            订单类型
	 * @return
	 */
	public static Long getNumber(String prefix) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmm");
		String orderNumber = sdf.format(new Date());

		for (int i = 0; i < 6; i++) {
			orderNumber += (int) (Math.random() * 10);
		}
		return Long.parseLong(prefix + orderNumber);
	}

	/**
	 * 生成订单号
	 * 
	 * @param orderType
	 *            订单类型
	 * @return
	 */
	public static String getNumber(String prefix, Integer ramdomLenght) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmSSS");
		String orderNumber = sdf.format(new Date());

		for (int i = 0; i < ramdomLenght; i++) {
			orderNumber += (int) (Math.random() * 10);
		}
		return prefix + orderNumber;
	}
	
	/**
	 * 生成订单号
	 * 
	 * @param orderType
	 *            订单类型
	 * @return
	 */
	public static String getNumber(String prefix,String memBerCode, Integer ramdomLenght) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmSSS");
		String orderNumber = sdf.format(new Date());

		for (int i = 0; i < ramdomLenght; i++) {
			orderNumber += (int) (Math.random() * 10);
		}
		return prefix +memBerCode+ orderNumber;
	}
	
	
	/**
	 * 生成订单号
	 * 
	 * @param orderType
	 *            订单类型
	 * @return
	 */
	public static String getSubAccNumber(String prefix) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String orderNumber = sdf.format(new Date());

		for (int i = 0; i < 6; i++) {
			orderNumber += (int) (Math.random() * 6);
		}
		return prefix + orderNumber;
	}
}
